AI Lessons
Lesson 8: Using the hand model & detecting multiple hands

Purpose: To use a pre-trained model that finds a hand in a live webcam picture, returns its keypoints as coordinates and use those coordinates in our game logic

No. of Classes

1 - (Time : 1 hour 30 minutes, Laptops/desktops : 10, Students strength : 15 to 20).

Materials Required

Computer/Laptop, Internet Connection, Webcam

Prior knowledge
  • Browsers
  • Basics of JavaScript - variables, functions and arrays
  • Drawing shapes on a p5.js canvas
  • The draw loop and displaying a webcam feed
Exercises

Exercise (1)



Exercise (2)



  • Part 1: Create a program that lets users draw in the air using their index finger.
  • Part 2: Extend the program to detect and track multiple hands at the same time.

Solutions



Teacher's Instruction:
  1. Check that the webcam works and note that ml5.js loads the model from the internet, so the internet connection is needed.
  2. Start from the base code linked in Exercise 1. It already has the variables and the empty steps, so the students fill in the model loading and the drawing rather than typing the whole program.
  3. Explain that this model is pre-trained - nobody in the class trained it. The program sends it a picture and it sends back a list of points.
  4. Show the keypoints image linked in Exercise 1. Draw out that the model returns 21 numbered points per hand, not the word “hand” - point 8 is the index fingertip, which is why the code picks that one.
  5. The results come back as an array, one entry per hand detected by the model. Detecting several hands is the same code reading more entries from that array.
  6. Discuss where gesture control is already used - games, phones, cars, even electric chimneys at home and malls.
  7. Points to Ponder:
    • We did not train this hand model. Somebody else did. What kind of pictures do you think they would have used to train it? Would it be supervised training or unsupervised training?
    • Where all do you think the hand model can be used in the real world? Discuss. Where would touch-free control be genuinely useful and where would it be worse than a button?